************************************************
************************************************

** Replication file for
** The correlates of discord: identity, issue alignment, and political hostility in polarized America.
** Author: Lori Bougher
** Journal: Political Behavior
** Note: Replication code for ANES Time Series data

************************************************
************************************************

*** ANES Time Series

	*** use file anests.dta file
	
	*** Scale conversion
		foreach var of varlist pidaw issalaw pidissue issuealign aware_dum affpol ingroupth outgroupth pidstr ideo_str polknow collegegrad male white age demvsrep repvsdem int_elec year exideo2 distOTH distOWN {
				su `var', meanonly  
				gen std_`var'=( `var'-r(min)) / (r(max)-r(min))
			}

	*** Figures and Tables
		* Table A.1
			su std_outgroupth std_ingroupth std_affpol std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_male std_repvsdem if pidstr>0 & pidstr<. [aw=weight] 
		* Table A.2
			pwcorr std_outgroupth std_ingroupth std_affpol std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow if pidstr>0 & pidstr<. [aw= weight]
		* Figure 1
			twoway (lpolyci std_outgroupth year [aw=weight], lpattern(solid)) (lpolyci std_ingroupth year [aw=weight]) (lpolyci std_issuealign year [aw=weight], lpattern(longdash)) (lpolyci std_pidstr year [aw=weight], lpattern(dash_dot_dot)), ///
				title("Figure 1: Trends in Affect, Partisan Strength, and Issue Alignment", size(medium)) ///
				xsc(range(1984 2012)) xlab(1984(4)2012) xtitle("Year") scheme(s2mono) ///
				note("Source: American National Election Study, Cumulative File, Presidential Years 1984-2012.", size(vsmall)) ///
				legend (symysize(*-.5) order(1 2 4 6 8) label(2 "Outgroup Affect") label(4 "Ingroup Affect") label(6 "Issue Alignment") label(8 "Strength of Party Identity") size(small))
		* Figure 2a
			graph twoway (scatter mpid1_wt year, connect(l) msize(small) mstyle(oh)) ///
				(scatter mpid2_wt year, connect(l) msize(small) mstyle(oh)) ///
				(scatter mpid3_wt year, connect(l) msize(small) mstyle(oh)), ///
				xsc(range(1984 2012)) xlab(1984(4)2012) yscale(r(0, 100), ) ylab(#6) ///
				legend(off) ytitle("") xtitle("") ysize(3) xsize(7)  ylabel(,glstyle(thin)) scheme(s2mono) ///
				text(15 1997 "{bf:Strong Partisans}", size(large)) text(45 1997 "{bf: Weak Partisans}", size(large)) text(75 1997 "{bf: Independent Leaners}", size(large)) ///
				text(95 1997 "{bf: Pure Independents}", size(large)) title("Figure 2a: Weighted Distributions for Partisan Strength", size(vlarge))
		* Figure 2b		
			graph twoway (scatter missue2_wt year, connect(l) msize(small) mstyle(oh)) ///
				(scatter missue3_wt year, connect(l) msize(small) mstyle(oh)), ///
				xsc(range(1984 2012)) xlab(1984(4)2012) yscale(r(0, 100), ) ylab(#6) ///
				legend(off) ytitle("") xtitle("") ysize(3) xsize(7)  ylabel(, glstyle(thin)) scheme(s2mono) ///
				text(15 1997 "{bf:Aligned (high issue alignment)}", size(large)) text(45 1997 "{bf: Middle (average issue alignment)}", size(large)) text(76 1997 "{bf: Unaligned (low issue alignment)}", size(large)) ///
				title("Figure 2b: Weighted Distributions for Issue Alignment", size(vlarge)) ///
				note("Source: American National Election Study, Cumulative File, Presidential Years 1984-2012.", size(small)) 
		* Figure 3a
			qui xtmixed c.outgroupth i.pidstr i.ideo_str i.issue2575 c.exideo2 i.int_elec i.polknow i.collegegrad c.age i.male i.white i.repvsdem i.year if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			qui margins pidstr#issue2575, at(year=(1984(4)2012)) 
			marginsplot, noci scheme(s2mono) ysc(range(20, 60)) ylab(20(10)60) ytitle("Linear Prediction") title("Figure 3a: Predicted Values of Outgroup Affect by Partisan Strength and Issue Alignment", size(medsmall)) subtitle(" ", size(tiny)) /// 
			legend(order(1 "Ind. Leaners, 25th %ile Issue Align." 2 "Ind. Leaners, 75th %ile Issue Align." 3 "Weak Partisans, 25th %ile Issue Align." 4 "Weak Partisans, 75th %ile Issue Align." 5 "Strong Partisans, 25th %ile Issue Align." 6 "Strong Partians, 75th %ile Issue Align.") size(small) keygap(1) symxsize(10))
		* Figure 3b
			qui xtmixed c.ingroupth i.pidstr i.ideo_str i.issue2575 c.exideo2 i.int_elec i.polknow i.collegegrad c.age i.male i.white i.repvsdem i.year if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			qui margins pidstr#issue2575, at(year=(1984(4)2012))  
			marginsplot, noci scheme(s2mono) ysc(range(60, 100)) ylab(60(10)100) ytitle("Linear Prediction") title("Figure 3b: Predicted Values of Ingroup Affect by Partisan Strength and Issue Alignment", size(medsmall)) subtitle(" ", size(tiny)) ///
			legend(order(1 "Ind. Leaners, 25th %ile Issue Align." 2 "Ind. Leaners, 75th %ile Issue Align." 3 "Weak Partisans, 25th %ile Issue Align." 4 "Weak Partisans, 75th %ile Issue Align." 5 "Strong Partisans, 25th %ile Issue Align." 6 "Strong Partians, 75th %ile Issue Align.") size(small) keygap(1) symxsize(10)) ///
			note("Source: American National Election Study, Cumulative File, Presidential Years 1984-2012.", size(vsmall))
		* Figure 4
			twoway(lpolyci std_distOTH std_issuealign [aw= weight])(lpolyci std_distOWN std_issuealign [aw=weight]), ///
				title("Figure 4: Perceived Self-to-Group Distance and Issue Alignment", size(medium)) ///
				xtitle("Issue Alignment", size(small)) ///
				ytitle("Perceived Distance (sum of squared differences)", size(small)) ///
				yscale(titlegap(*5)) scheme(s2mono) ///
				note("Source: American National Election Study, Cumulative File, Presidential Years 1984-2012.", size(vsmall)) ///
				legend (symysize(*-.5) label(2 "Perceived Distance from Other Party")label(3 "Perceived Distance from Own Party") size(small) keygap(1) symxsize(10))
		* Table 1
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_ingroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_affpol std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem  if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
		* Table 2
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. & pidstr==1 [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. & pidstr==2 [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. & pidstr==3 [pw= weight]  || year:, mle cov(unstructured) 
		* Table 3
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_aware_dum std_issalaw std_pidaw std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_ingroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_aware_dum std_issalaw std_pidaw std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_aff std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_aware_dum std_issalaw std_pidaw std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
		* Table A.3 
			xtmixed std_outgroup std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_outgroup std_pidstr std_ideo_str std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
			xtmixed std_outgroup std_pidstr std_ideo_str std_issuealign std_exideo2 std_int_elec std_polknow std_pidissue std_collegegrad std_age std_male std_white std_repvsdem if affpol<. [pw= weight]  || year:, mle cov(unstructured) 
